﻿namespace Microsoft.SmallBasic.Library
{
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Net;
    using System.Globalization;

    [SmallBasicType]
    public static class Network
    {
        public static Primitive DownloadFile(Primitive url)
        {
            // TODO:
            return null;
        }

        internal static Primitive GetLocalFile(Primitive fileNameOrUrl)
        {
            Uri uri;
            if (fileNameOrUrl.IsEmpty)
            {
                return fileNameOrUrl;
            }
            if (!Uri.TryCreate((string)fileNameOrUrl, UriKind.RelativeOrAbsolute, out uri) || !uri.IsAbsoluteUri)
            {
                return fileNameOrUrl;
            }
            if (uri.Scheme.ToLower(CultureInfo.InvariantCulture) == "file")
            {
                return fileNameOrUrl;
            }
            return DownloadFile(fileNameOrUrl);
        }

        public static Primitive GetWebPageContents(Primitive url)
        {
            if (url.IsEmpty)
            {
                return url;
            }
            return GetWebPageContents((string) url);
        }

        internal static string GetWebPageContents(string url)
        {
            // TODO:
            return null;
        }
    }
}

